package com.peihua.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.peihua.domain.Result;
import com.peihua.domain.Rider;
import com.peihua.service.RiderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *parm: Rider -->骑手信息
 * @author
 * @since 2025-09-14
 */
@RestController
@RequestMapping("/rider")
public class RiderController {
    @Autowired
    private RiderService riderService;

    @PostMapping("/add")
    public Result add(@RequestBody Rider rider){
        if(Objects.isNull(rider)){
            return Result.error("未输入信息");
        }
        LambdaQueryWrapper<Rider> eq = new LambdaQueryWrapper<Rider>().eq(Rider::getRiderPhone, rider.getRiderPhone());
        Rider one = riderService.getOne(eq);
        if(Objects.isNull(one)){
            riderService.save(rider);
        }else{
            return Result.error(500L,"该手机号已使用");
        }
        return Result.success("success");
    }

    @GetMapping("/getAll")
    public Result getAll(){
        List<Rider> list = riderService.list();
        return Result.success(list);
    }
}
